<template>
	<view class="content">
		<view   :class="show ? 'fade-in' : 'fade-out'">
			<tn-swiper mode="none" :list="list" :height="240" :radius="20" @click="swiperClick"></tn-swiper>
			<view class="title">活动报名</view>
			<view class="ftitle">参与线下活动和小伙伴一起海皮！</view>
			<view class="list">
				<view class="list-item tn-flex" v-for="(item,index) in activityList" :key="index"
					@click="goUser(item.id)" :class="['animated','fadeInUp']">
					<image :src="item.logo" class="avatar" mode=""></image>
					<view class="user">
						<view class="city-num">
							<text class="city">{{item.title}}</text>
							<text class="num">{{item.viewUser.viewUserCount}}人参与</text>
						</view>
						<view class="time">举办时间：{{ item.times }}</view>
						<view class="browse">
							<view class="browse-item">
								<image src="/static/index/yan.png" mode="" class="img1"></image>
								<text>{{ item.view_num }}</text>
							</view>
							<view class="browse-item">
								<image src="/static/index/redu.png" mode="" class="img2"></image>
								<text>{{ item.viewUser.viewUserCount }}</text>
							</view>
							
							<view class="browse-item" v-if="item.is_ding == 1" >
								<image src="/static/index/ding1.png" class="img2" ></image>
							</view>
							
						</view>
					</view>
				</view>
			</view>
			<view class="tn-load-more">
				<tn-load-more :status="status"></tn-load-more>
			</view>

			<view class="add-icon" @click="navigateToFn({ url: '/circlePages/create', checkLogin: true })">
				<image src="https://peiwanblogs.huolieniaowangluo.com/wx-image/wfw/addactivity.png" mode=""></image>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [],
				page: 1,
				activityList: [],
				status: 'loadmore',
				show: false
			}
		},
		async onLoad() {
			console.log('触发了')
			 this.getBanner()
			 this.getList(1)
		},
		onReachBottom() {
			this.status = 'loading'
			this.page++

			this.getList()
		},

		methods: {
			async getList(loading) {
				let result = await this.$request({
					loading,
					method: 'post',
					url: '/api/index/allActiveList',
					data: {
						key: '',
						page: this.page,
						type: 'list'
					}
				})
				let data = result.data.data.data
				if (this.page == 1) {
					this.activityList = data
					this.show = true
				} else {
					this.activityList = this.activityList.concat(data)
					if (data.length == 0) {
						this.page--
						this.status = 'nomore'
					}
				}
			},
			async getBanner(){
				try{
					let result = await this.$request({
						loading:0,
						method:'post',
						url:'/api/index/activeBanner'
					})
					console.log(result.data.data)
					this.list = result.data.data
				}catch(e){
					//TODO handle the exception
				}
			},
			// 跳转
			goUser(id) {
				uni.navigateTo({
					url: '/circlePages/reserve?id='+id
				});
			},
			swiperClick(e){
				let id = this.list[e].url
				uni.navigateTo({
					url: '/circlePages/reserve?id='+id
				});
			}
		}
	}
</script>
<style lang="scss" scoped>
	.content {
		padding: 24rpx 30rpx;
		.title {
			font-size: 36rpx;
			font-weight: bold;
			color: #080808;
			margin-top: 32rpx;

		}

		.ftitle {
			font-size: 24rpx;
			font-weight: 400;
			color: #999999;
			margin-top: 14rpx;
		}

		.list {
			.animated {
				animation-duration: 0.5s;
				animation-fill-mode: both;
			}

			.fadeInUp {
				animation-name: fadeInUp;
			}

			@keyframes fadeInUp {
				0% {
					opacity: 0;
					transform: translateY(30px);
				}

				100% {
					opacity: 1;
					transform: translateY(0);
				}
			}

			.list-item {
				height: 176rpx;
				background:#f7f7f7;
				border-radius: 20rpx;
				display: flex;
				align-items: center;
				padding: 0 24rpx;
				margin-top: 24rpx;

				.avatar {
					width: 128rpx;
					height: 128rpx;
					border-radius: 50%;
				}

				.user {
					flex: 1;
					padding-left: 24rpx;

					.city-num {
						display: flex;
						justify-content: space-between;

						.city {
							font-size: 30rpx;
							font-weight: 400;
							color: #333333;
						}

						.num {
							font-size: 26rpx;
							font-weight: 400;
							color: #333333;
						}
					}

					.time {
						font-size: 24rpx;
						font-weight: 400;
						color: #3333339e;
						margin: 10rpx 0 13rpx 0;
					}

					.browse {
						display: flex;
						align-items: center;

						.browse-item {
							display: flex;
							align-items: center;
							margin-right: 32rpx;

							.img1 {
								width: 26rpx;
								height: 18rpx;
							}

							.img2 {
								width: 18rpx;
								height: 21rpx;
							}

							text {
								font-size: 22rpx;
								font-weight: 400;
								color: #333333;
								margin-left: 6rpx;
							}
						}
					}
				}
			}
		}

		.tn-load-more {
			padding: 20rpx 0;
		}

		.add-icon {
			position: fixed;
			right: 30rpx;
			bottom: 600rpx;
			animation: suspension 3s ease-in-out infinite;

			image {
				width: 108rpx;
				height: 108rpx;
			}
		}

		@keyframes suspension {

			0%,
			100% {
				transform: translateY(0);
			}

			50% {
				transform: translateY(50rpx);
			}
		}
	}
</style>
